package com.chinadci.smartcommunitysystembackstage.controller;


import com.chinadci.smartcommunitysystembackstage.entity.Clbx;
import com.chinadci.smartcommunitysystembackstage.entity.ScsPhone;
import com.chinadci.smartcommunitysystembackstage.service.ScsActivityService;
import com.chinadci.smartcommunitysystembackstage.service.ScsPhoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Code Duck
 * @since 2021-04-13
 */
@CrossOrigin
@RestController
@Api("建业E家")
public class ScsPhoneController {
    @Autowired
    private ScsPhoneService service;

    //查询所有便民电话
    @ApiOperation(value = "查询所有便民电话")           //swagger
    @ApiImplicitParam(name = "name",value = "姓名")       //表明要传入的参数
    @RequestMapping(value = "/api/bmdhfind",method = RequestMethod.GET)
    public Map Finds(String name){
        Map<String,Object> map=new HashMap<>();
        map.put("data",service.Find(name));
        return map;
    }

    //新增便民电话
    @ApiOperation(value = "新增便民电话")           //swagger
    @ApiImplicitParam(name = "ScsPhone",value = "对象")       //表明要传入的参数
    @RequestMapping(value = "/api/bmdhinsert",method = RequestMethod.POST)
    public Map Insert(ScsPhone scs){
        Map<String,Object> map=new HashMap<>();
        if (service.Finds(scs.getPPhone())!=null){
                map.put("phone",0);     //如果是0证明该电话号码已经存在
            return map;
        }
        map.put("phone",1);
        map.put("data",service.Insert(scs));
        return map;
    }

    //修改便民电话
    @ApiOperation(value = "修改便民电话")           //swagger
    @ApiImplicitParam(name = "name",value = "姓名")       //表明要传入的参数
    @RequestMapping(value = "/api/bmdhxg",method = RequestMethod.POST)
    public Map Update(ScsPhone scs){
        Map<String,Object> map=new HashMap<>();
        map.put("data",service.Update(scs));
        return map;
    }

    //删除便民电话
    @ApiOperation(value = "删除便民电话")           //swagger
    @ApiImplicitParam(name = "id",value = "便民电话编号")       //表明要传入的参数
    @RequestMapping(value = "/api/bmdhdel",method = RequestMethod.POST)
    public Map Del(int id){
        Map<String,Object> map=new HashMap<>();
        map.put("data",service.Del(id));
        return map;
    }

    //修改的时候查找
    @ApiOperation(value = "修改的时候查找")           //swagger
    @ApiImplicitParam(name = "id",value = "便民电话编号")       //表明要传入的参数
    @RequestMapping(value = "/api/bmdhcx",method = RequestMethod.GET)
    public Map Finds(int id){
        Map<String,Object> map=new HashMap<>();
        map.put("data",service.Find(id));
        return map;
    }
}
